from django.conf.urls.defaults import *
from django.contrib.auth.views import login, logout_then_login
from django.contrib import admin

from wanbooks.catalog.views import edition_list
from wanbooks.sharing.views import main_page, upload_gbs_xml

from wanbooks.catalog.models import Edition

admin.autodiscover()

urlpatterns = patterns('',
    (r'^pac/', include('wanbooks.catalog.urls')),

    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    (r'^admin/(.*)', admin.site.root),

    (r'^login/$',  login, {'template_name':'login.html'}),
    
    ### how to make this redirect to the main_page, w/o hardcoding the URL?
    (r'^logout/$', logout_then_login, {'login_url':'/'}),

    (r'^add_items/$', upload_gbs_xml),
    
    (r'^$', main_page),
)

# only for development
from django.conf import settings

if settings.DEBUG:
    from django.contrib.auth.decorators import login_required
    from django.contrib import databrowse
    from catalog.models import Edition, Credit, Creator
    from sharing.models import Item, Lease
    databrowse.site.register(Edition)
    databrowse.site.register(Credit)
    databrowse.site.register(Creator)
    databrowse.site.register(Item)
    databrowse.site.register(Lease)
    
    import os
    PROJECT_ROOT = os.path.dirname(__file__)
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve',
            {'document_root': os.path.join(PROJECT_ROOT,'static')}),
        (r'^db/(.*)', login_required(databrowse.site.root)),
    )
